﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.BlackApart.Business.Calendar;

namespace blackhouse.BlackApart.Business.Apartments {
    public class ImpApartment : IApartment {

        #region Fields

        private IApartmentLocation location;

        #endregion

        #region Properties

        public int Id { get; set; }

        public int NumberOfPeople { get; set; }

        public IApartmentLocation Location {
            get {
                if (this.location == null)
                    this.location = Factory.Instance().GetApartmentLocation();
                return this.location;
            }
            set { this.location = value; }
        }

        public float AreaSize { get; set; }

        public string Name { get; set; }

        public IApartmentGroup Group { get; set; }

        #endregion

        #region Methods

        public bool Save() {
            if (this.Group == null || !this.Group.Exists())
                throw new ExceptionUndefinedApartmentGroup();
            return
                !string.IsNullOrEmpty(this.Name)
                && this.NumberOfPeople > 0
                && this.AreaSize > 0;
        }

        //public ICalendar GetCalendar(DateTime startDate, DateTime endDate) {
        //    return Factory.Instance().GetApartmentCalendar(this, startDate, endDate);
        //}

        public IApartment[] GetAllFreeApartments(DateTime strtDate, DateTime endDate) {
            throw new NotImplementedException();
        }

        public IApartment[] GetAllFreeApartments(DateTime strtDate, DateTime endDate,int apartmentGropId) {
            throw new NotImplementedException();
        }

        public IApartment[] GetApartmentsByGroup(int groupId) {
            throw new NotImplementedException();
        }

        #endregion

        #region Equals Methods

        public override bool Equals(object obj) {
            IApartment apartment = obj as IApartment;
            if (apartment == null) return false;
            return apartment.Id == this.Id;
        }

        public override int GetHashCode() {
            return this.Id;
        }

        public override string ToString() {
            return this.Name;
        }

        #endregion

    }
}
